<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="审核结果" prop="auditResult">
        <el-input
          v-model="queryParams.auditResult"
          placeholder="请输入审核结果"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select
          v-model="queryParams.auditStatus"
          placeholder="请选择"
          clearable
          @keyup.enter.native="handleQuery"
        > 
          <el-option label="未审核" :value="0" />
          <el-option label="驳回" :value="-1" />
          <el-option label="通过" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" width="50"/>
      <el-table-column label="申请账号" align="center" prop="sysUser" >
        <template slot-scope="scope">{{ scope.row.sysUser === null ? '未知用户':scope.row.sysUser.userName}}</template>
      </el-table-column>
      <el-table-column label="申请主体" align="center" prop="realName" >
        <template slot-scope="scope">{{ scope.row.realName}}</template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请类别" align="center" prop="proveType" width="180">
        <template slot-scope="scope">
          <span v-if="scope.row.proveType === -2">认证驳回</span>
          <span v-if="scope.row.proveType === -1">认证审核中</span>
          <span v-if="scope.row.proveType === 0">未认证</span>
          <span v-if="scope.row.proveType === 1">个人用户</span>
          <span v-if="scope.row.proveType === 2">私人企业</span>
          <span v-if="scope.row.proveType === 3">国有重点企业</span>
          <span v-if="scope.row.proveType === 4">组织机构</span>
          <span v-if="scope.row.proveType === 5">事业单位</span>
          <span v-if="scope.row.proveType === 6">普通局委办</span>
          <span v-if="scope.row.proveType === 7">权力机构</span>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核结果" align="center" prop="auditResult">
        <template slot-scope="scope">
          <span>{{ scope.row.auditResult ? scope.row.auditResult:'-' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="auditStatus" width="180">
        <template slot-scope="scope">
          <span style="color: red" v-if="scope.row.auditStatus === -1">驳回</span>
          <span style="color: #3A71A8" v-if="scope.row.auditStatus === 0">未审核</span>
          <span style="color: #1ab394" v-if="scope.row.auditStatus === 1">通过</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.auditStatus == 0"
                     size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="handleUpdate(scope.row)"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 对用户认证信息进行审核 -->
    <el-dialog title="认证审核" :visible.sync="auditFormOpen" width="1000px" append-to-body>
      <el-form ref="auditForm" :model="auditForm" label-width="120px">
        <el-row v-if="auditForm.sysUser">
          <el-col :span="12">
            <el-form-item label="申请账号：">
              {{auditForm.sysUser.nickName}}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="真实姓名：">
              {{auditForm.realName}}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请时间：">
              <span>{{ parseTime(auditForm.updateTime, '{y}-{m}-{d}') }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请类别：">
              <span v-if="auditForm.proveType === -2">认证驳回</span>
              <span v-else-if="auditForm.proveType === -1">认证审核中</span>
              <span v-else-if="auditForm.proveType === 0">未认证</span>
              <span v-else-if="auditForm.proveType === 1">个人用户</span>
              <span v-else-if="auditForm.proveType === 2">私人企业</span>
              <span v-else-if="auditForm.proveType === 3">国有重点企业</span>
              <span v-else-if="auditForm.proveType === 4">组织机构</span>
              <span v-else-if="auditForm.proveType === 5">事业单位</span>
              <span v-else-if="auditForm.proveType === 6">普通局委办</span>
              <span v-else-if="auditForm.proveType === 7">权力机构</span>
            </el-form-item>
          </el-col>
          <el-row v-if="auditForm.proveType === 1">
            <el-col :span="12">
              <el-form-item label="身份证正面：">
                <img :src="auditForm.idCardFrontFile" style="width:300px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证反面：">
                <img :src="auditForm.idCardFrontBack" style="width:300px"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-else>
            <el-col :span="12">
              <el-form-item label="营业执照或法人证件：">
                <img :src="auditForm.businessLicense" style="width:300px"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-row>
        <el-row>
            <el-form-item label="审核结果：" prop="auditStatus">
              <el-radio v-model="auditForm.auditStatus" :label="1">通过</el-radio>
              <el-radio v-model="auditForm.auditStatus" :label="-1">驳回</el-radio>
            </el-form-item>
            <el-form-item label="驳回理由：" prop="auditResult" v-if="auditForm.auditStatus === -1">
              <el-input v-model="auditForm.auditResult" type="textarea" :rows="3" placeholder="请输入驳回理由" />
            </el-form-item>
        </el-row>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAuditForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProveLog, auditUserProve } from "@/api/qysj/audit/api.js";

export default {
  name: "audit-prove",
  data() {
    return {
      loading: true,// 遮罩层
      ids: [],// 选中数组
      single: true,// 非单个禁用
      multiple: true,// 非多个禁用
      showSearch: true,// 显示搜索条件
      total: 0,// 总条数
      logList: [],// 审核记录表格数据
      title: "",// 弹出层标题
      open: false,// 是否显示弹出层
      auditFormOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      
      form: {},// 表单参数
      auditForm: {// 审核表单参数
        auditStatus: null,
        auditResult: null,
        id: null,
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询审核记录列表 */
    getList() {
      this.loading = true;
      listProveLog(this.queryParams).then(response => {
        this.logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.auditFormOpen = false;
      this.reset();
      this.getList();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        auditUserId: null,
        associateId: null,
        type: null,
        result: null,
        remark: null,
        status: "0",
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 提交按钮 */
    submitAuditForm() {
      auditUserProve(this.auditForm).then(response => {
        this.$modal.msgSuccess("审核完成");
        this.auditFormOpen = false;
        this.getList();
      });
    },
    handleUpdate(row){
      this.auditForm = row
      this.auditFormOpen = true;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除审核记录编号为"' + ids + '"的数据项？').then(function() {
        return delLog(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/log/export', {
        ...this.queryParams
      }, `log_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
